package com.bdqn.desiremall.command;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.bdqn.desiremall.entity.Mall_AdminiStrator;
import com.bdqn.desiremall.entity.Mall_User;
import com.bdqn.desiremall.serivce.admin.AdminService;
import com.bdqn.desiremall.serivce.admin.AdminServiceImpl;
import com.desiremall.util.Constants;
import com.mvc.command.ICommand;




public class AdmimCommand implements ICommand {
//调用admin服务层
	AdminService adminService = new AdminServiceImpl();
	
	//后台登录
	public void login(HttpServletRequest request,HttpServletResponse response){
		PrintWriter out = null;
		String adminName = request.getParameter("adminiName");
		String password = request.getParameter("adminiPassword");	
		Mall_AdminiStrator admin = adminService.Login(adminName, password);
		HttpSession session = request.getSession();
		try {
			out=response.getWriter();
		    if (null!=admin) {
		    	session.setAttribute("admin", admin);
		    	response.sendRedirect("index.jsp");
		    }else{
		    	out.write("false");
		    	out.flush();
		    	out.close();
		    }
		    
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
		
	}
	
	/**
	 * 查看所有用户列表
	 * @param request
	 * @param response
	 */
	public void userList(HttpServletRequest request, HttpServletResponse response) {
		Mall_User user = new Mall_User();
		List<Mall_User> userView = adminService.userView(user);
		HttpSession session = request.getSession();
		//int i = userView.size();
		//System.out.println(i);
		//System.out.println("用户状态"+userView.get(0).getUserState());
		session.setAttribute("userlist", userView);
		/*try {
			//request.getRequestDispatcher("/Backstage/jsp/member-list.jsp").forward(request, response);
		} catch (ServletException | IOException e) {
			
			e.printStackTrace();
		}*/
	}
	
	/**
	 *是否拉黑用戶
	 * @param request
	 * @param response
	 */
	public void defriend(HttpServletRequest request, HttpServletResponse response){
		int id =Integer.parseInt(request.getParameter("id"));
		int state = Integer.parseInt(request.getParameter("state"));
		System.out.println("状态"+state);
		adminService.defriendUser(id,state);
		
	}
}
